﻿using System;

namespace HeroDream
{
    /// <summary>
    /// 递归类
    /// </summary>
    class Recursive
    {
        /// <summary>
        /// 老和尚说故事
        /// </summary>
        /// <param name="time"></param>
        public void Story(int time)
        {
            if (time == 0) return;//循环退出条件
            time--;
            Console.WriteLine("从前有座山，山里有座庙，庙里有个老和尚，老和尚对小和尚说：");
            Story(time);
        }

        /// <summary>
        /// 询问座位号为index的人号码牌是多少
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public int RequestNumber(int index)
        {
            if (index == 1) return 300;
           int lastNumber=  RequestNumber(index - 1);
           return lastNumber + 1;
        }

        /// <summary>
        /// 求阶乘
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public int Factorial(int n)
        {
            if (n == 1) return 1;
            //2的阶乘=2*1的阶乘
            return n * Factorial(n - 1);
        }

        /// <summary>
        /// 求斐波那契数列
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public int Fibonacci(int n)
        {
            if (n == 1) return 1; 
            if (n == 2) return 1;
            int v = Fibonacci(n - 1) + Fibonacci(n - 2);
            return v;
        }

        public static void Test()
        {
            Recursive recursive = new Recursive();
            int time = 10;
            recursive.Story(time);
            Console.WriteLine(recursive.RequestNumber(9));
            Console.WriteLine(recursive.Factorial(5));
        }

    }
}
